﻿using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

namespace IQIGame.Onigao.GamePlay
{
    [Serializable]
    public class BattleLoopClip : PlayableAsset, ITimelineClipAsset
    {
        public override double duration => 1.0;
        
        public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
        {
            var rPlayable = ScriptPlayable<BattleLoopBehaviour>.Create(graph);
            BattleLoopBehaviour clone = rPlayable.GetBehaviour();
            var rEntityDriver = owner.GetComponent<EntityDriver>();
            var rUnitView = BattleClientUtil.GetUnitViewByEntityDriver(rEntityDriver);
            if (rUnitView != null)
            {
                clone.timelineComp = rUnitView.GetComponent<BattleTimelineComponent>(ETComponentType.BattleTimelineComponent);
            }
            return rPlayable;
        }

        public ClipCaps clipCaps => ClipCaps.None;
    }
}